package com.changgou.order.controller;

import com.changgou.order.feign.CartFeign;
import com.changgou.order.feign.OrderFeign;
import com.changgou.pojo.Address;
import com.changgou.pojo.Order;
import com.changgou.pojo.OrderItem;
import com.changgou.user.feign.AddressFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 老大哥在看着你
 *
 * @author ANG.YU
 * @date 2019-10-22 21:39
 */
@Controller
@RequestMapping("/worder")
public class WOrderController {
    @Autowired
    private AddressFeign addressFeign;
    @Autowired
    private CartFeign cartFeign;
    @Autowired
    private OrderFeign orderFeign;

    @GetMapping("/ready")
    public String ready(Model model) {
        List<Address> addressList = addressFeign.getAddList("sunwukong");
        Address defaultAddress = new Address();
        for (Address address : addressList) {
            if (address.getIsDefault().equals("1")) {
                defaultAddress = address;
            }
        }
        model.addAttribute("addressList", addressList);
        Map cartMap = cartFeign.findReadyCartList();
        model.addAttribute("defaultAddress", defaultAddress);
        model.addAttribute("cartMap", cartMap);
        return "order";
    }

    @GetMapping("/submit")
    public String submit(Order order) {
        orderFeign.add(order);
        return "wxpay";
    }
}
